<?php namespace Phpcmf\Controllers;

class Son extends \Phpcmf\Home\Mform
{

    public function index() {
        $this->_Home_Show();
    }

    public function show() {
        $this->_Home_Show();
    }
	/**
	 * 收藏
	 */
	public function quan() {
	    //$id = (int)\Phpcmf\Service::L('input')->get('id');
		$this->_module_init($mid);
		$rt = \Phpcmf\Service::M('op', 'quan')->run(SITE_ID.'_'.MOD_DIR.$mid, $mid);
	    //$rt = \Phpcmf\Service::M('op', 'quan')->run($this->tablename, $id);
	    $this->_json($rt['code'], $rt['msg'], $rt['data'], $rt['datas']);
	}
	/**
	 * 点赞
	 */
	public function zan() {
	    //$id = (int)\Phpcmf\Service::L('input')->get('id');
		$this->_module_init($mid);
		$rt = \Phpcmf\Service::M('op', 'quan')->zan(SITE_ID.'_'.MOD_DIR.$mid, $mid);
	    //$rt = \Phpcmf\Service::M('op', 'quan')->run($this->tablename, $id);
	    $this->_json($rt['code'], $rt['msg'], $rt['data']);
	}
	/**
	 * 点赞列表
	 */
	public function zanlian() {
	    $id = (int)\Phpcmf\Service::L('input')->get('id');
		$this->_module_init($mid);
		$rt = \Phpcmf\Service::M('op', 'quan')->zan(SITE_ID.'_'.MOD_DIR.$mid, $mid, $id);
	    //$rt = \Phpcmf\Service::M('op', 'quan')->run($this->tablename, $id);
	    $this->_json($rt['code'], $rt['msg'], $rt['data'], $rt['datas']);
	}

    protected function _Call_Show($data) {

        $_test_0 = 0;
        $_test_1 = [];
        $data['prev_page'] = $data['next_page'] = [];

        $son = \Phpcmf\Service::M()->table(SITE_ID.'_'.MOD_DIR.'_form_son')
            ->where('cid', $data['cid'])
            ->where('status=1')
            ->order_by('displayorder asc,id asc')->getAll();
        if ($son) {
            foreach ($son as $i => $t) {
                $son[$i]['url'] = dr_son_url($t);
                if ($t['id'] == $data['id']) {
                    // 找到了
                    $_test_0 = 1;
                    $data['prev_page'] = $_test_1;
                } elseif ($_test_0) {
                    $_test_0 = 0;
                    $data['next_page'] = $son[$i];
                }
                $_test_1 = $son[$i];
            }
        }

        $data['cneirong'] = dr_strcut(dr_clearhtml($data['neirong']), 100);
        $data['son_list'] = \Phpcmf\Service::M('content', 'quan')->format_son_list($son, $this->index['son_type']);
        $data['son_type'] = \Phpcmf\Service::M('content', 'quan')->format_son_type($this->index['son_type']);
        $data['ctitle'] = $this->index['title'];
        $data['tname'] = $data['son_type'][$data['tid']];

        return $data;
    }
}
